################################################################################################
################################################################################################
#### Levels of Linkage: Across-Agreement v. Within-Agreement Explanations of Consensus Formation Among States   ###
###   Heather McKibben & Shaina Western ##############################################################
################################################################################################
################################################################################################

### Load Packages and Functions Necessary to Get and Analyze Draws 
###
library(coda)
library(foreign)
library(MCMCpack)

#Function to extract from coda objects
extractCodaDraws <- function(x, vars=varnames(x)) {
  # Checks
  if( class(x) != "mcmc.list" ) {
    stop("extractCodaDraws requires an object of class 'mcmc.list'")
  }
  for(vn in vars) {
    if( !(vn %in% varnames(x)) ) {
      stop("Each varible selected must exist in the 'mcmc.list'")
    }
  }
  # extract draws
  out <- sapply(vars, function(vn) unlist(lapply(x, function(tc) tc[,vn])))
  rownames(out) <- NULL
  return( as.data.frame(out) )
}



### Load Data ###
DataSet <- read.csv("Dataset for EU Consensus behavior McKibben-Western 2010-10-17-5.csv")
DataSet$LogPolicyLink <- log(DataSet$Policy.Macro.Linkage)
DataSet$LogTemporalLink <- log(DataSet$Temporal.Macro.Linkage)
DataSet$Consensus <- c(rep(NA, 70))
for(i in 1:length(DataSet$Consensus)){
	DataSet$Consensus[i] <- ifelse(DataSet$QMV[i]==0, 1, 0)
}

DataSet$LogCouncilLink <- log(DataSet$p0 + 1)

################################################################################################
################################################################################################
### Model 1 ####################################################################################
################################################################################################
################################################################################################

Model1.1a <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model1.1b <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model1.1c <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogPolicyLink +  LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model1.1 <- mcmc.list(Model1.1a, Model1.1b, Model1.1c)



Model1.2a <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model1.2b <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model1.2c <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model1.2 <- mcmc.list(Model1.2a, Model1.2b, Model1.2c)


Model1.3a <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model1.3b <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model1.3c <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model1.3 <- mcmc.list(Model1.3a, Model1.3b, Model1.3c)

Model1.4a <- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model1.4b <- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model1.4c<- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model1.4 <- mcmc.list(Model1.4a, Model1.4b, Model1.4c)

Model1.5a <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model1.5b <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model1.5c <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogPolicyLink + LogTemporalLink + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model1.5 <- mcmc.list(Model1.5a, Model1.5b, Model1.5c)

summary(Model1.1)
summary(Model1.2)
summary(Model1.3)
summary(Model1.4)
summary(Model1.5)

DrawModel1.1 <- extractCodaDraws(Model1.1)
DrawModel1.2 <- extractCodaDraws(Model1.2)
DrawModel1.3 <- extractCodaDraws(Model1.3)
DrawModel1.4 <- extractCodaDraws(Model1.4)
DrawModel1.5 <- extractCodaDraws(Model1.5)


mean(DrawModel1.1$Microlink_ODMB1>0)
mean(DrawModel1.2$Microlink_ODMB2>0)
mean(DrawModel1.3$Microlink_ODMB3>0)
mean(DrawModel1.4$Microlink_ODMB4>0)
mean(DrawModel1.5$Microlink_ODMB5>0)

mean(DrawModel1.1$LogPolicyLink>0)
mean(DrawModel1.2$LogPolicyLink>0)
mean(DrawModel1.3$LogPolicyLink>0)
mean(DrawModel1.4$LogPolicyLink>0)
mean(DrawModel1.5$LogPolicyLink>0)

mean(DrawModel1.1$LogTemporalLink>0)
mean(DrawModel1.2$LogTemporalLink>0)
mean(DrawModel1.3$LogTemporalLink>0)
mean(DrawModel1.4$LogTemporalLink>0)
mean(DrawModel1.5$LogTemporalLink>0)

mean(DrawModel1.1$LogCouncilLink>0)
mean(DrawModel1.2$LogCouncilLink>0)
mean(DrawModel1.3$LogCouncilLink>0)
mean(DrawModel1.4$LogCouncilLink>0)
mean(DrawModel1.5$LogCouncilLink>0)



################################################################################################
################################################################################################
### Model 2 ####################################################################################
################################################################################################
################################################################################################

Model2.1a <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogPolicyLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model2.1b <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogPolicyLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model2.1c <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogPolicyLink +   
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model2.1 <- mcmc.list(Model2.1a, Model2.1b, Model2.1c)



Model2.2a <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogPolicyLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model2.2b <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogPolicyLink +
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model2.2c <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogPolicyLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model2.2 <- mcmc.list(Model2.2a, Model2.2b, Model2.2c)


Model2.3a <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogPolicyLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model2.3b <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogPolicyLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model2.3c <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogPolicyLink +
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model2.3 <- mcmc.list(Model2.3a, Model2.3b, Model2.3c)

Model2.4a <- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogPolicyLink +
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model2.4b <- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogPolicyLink +
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model2.4c<- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogPolicyLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model2.4 <- mcmc.list(Model2.4a, Model2.4b, Model2.4c)

Model2.5a <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogPolicyLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model2.5b <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogPolicyLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model2.5c <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogPolicyLink +
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model2.5 <- mcmc.list(Model2.5a, Model2.5b, Model2.5c)

summary(Model2.1)
summary(Model2.2)
summary(Model2.3)
summary(Model2.4)
summary(Model2.5)

DrawModel2.1 <- extractCodaDraws(Model2.1)
DrawModel2.2 <- extractCodaDraws(Model2.2)
DrawModel2.3 <- extractCodaDraws(Model2.3)
DrawModel2.4 <- extractCodaDraws(Model2.4)
DrawModel2.5 <- extractCodaDraws(Model2.5)


mean(DrawModel2.1$Microlink_ODMB1>0)
mean(DrawModel2.2$Microlink_ODMB2>0)
mean(DrawModel2.3$Microlink_ODMB3>0)
mean(DrawModel2.4$Microlink_ODMB4>0)
mean(DrawModel2.5$Microlink_ODMB5>0)

mean(DrawModel2.1$LogPolicyLink>0)
mean(DrawModel2.2$LogPolicyLink>0)
mean(DrawModel2.3$LogPolicyLink>0)
mean(DrawModel2.4$LogPolicyLink>0)
mean(DrawModel2.5$LogPolicyLink>0)


################################################################################################
################################################################################################
### Model 3 ####################################################################################
################################################################################################
################################################################################################

Model3.1a <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model3.1b <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model3.1c <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogTemporalLink +  
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model3.1 <- mcmc.list(Model3.1a, Model3.1b, Model3.1c)



Model3.2a <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model3.2b <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogTemporalLink +  
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model3.2c <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model3.2 <- mcmc.list(Model3.2a, Model3.2b, Model3.2c)


Model3.3a <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model3.3b <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model3.3c <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model3.3 <- mcmc.list(Model3.3a, Model3.3b, Model3.3c)

Model3.4a <- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model3.4b <- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogTemporalLink +  
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model3.4c<- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model3.4 <- mcmc.list(Model3.4a, Model3.4b, Model3.4c)

Model3.5a <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model3.5b <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model3.5c <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogTemporalLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model3.5 <- mcmc.list(Model3.5a, Model3.5b, Model3.5c)

summary(Model3.1)
summary(Model3.2)
summary(Model3.3)
summary(Model3.4)
summary(Model3.5)

DrawModel3.1 <- extractCodaDraws(Model3.1)
DrawModel3.2 <- extractCodaDraws(Model3.2)
DrawModel3.3 <- extractCodaDraws(Model3.3)
DrawModel3.4 <- extractCodaDraws(Model3.4)
DrawModel3.5 <- extractCodaDraws(Model3.5)


mean(DrawModel3.1$Microlink_ODMB1>0)
mean(DrawModel3.2$Microlink_ODMB2>0)
mean(DrawModel3.3$Microlink_ODMB3>0)
mean(DrawModel3.4$Microlink_ODMB4>0)
mean(DrawModel3.5$Microlink_ODMB5>0)

mean(DrawModel3.1$LogTemporalLink>0)
mean(DrawModel3.2$LogTemporalLink>0)
mean(DrawModel3.3$LogTemporalLink>0)
mean(DrawModel3.4$LogTemporalLink>0)
mean(DrawModel3.5$LogTemporalLink>0)


################################################################################################
################################################################################################
### Model 4 ####################################################################################
################################################################################################
################################################################################################

Model4.1a <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model4.1b <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model4.1c <- MCMClogit(Consensus2 ~ Microlink_ODMB1 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model4.1 <- mcmc.list(Model4.1a, Model4.1b, Model4.1c)



Model4.2a <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model4.2b <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model4.2c <- MCMClogit(Consensus2 ~ Microlink_ODMB2 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model4.2 <- mcmc.list(Model4.2a, Model4.2b, Model4.2c)


Model4.3a <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model4.3b <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model4.3c <- MCMClogit(Consensus2 ~ Microlink_ODMB3 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model4.3 <- mcmc.list(Model4.3a, Model4.3b, Model4.3c)

Model4.4a <- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model4.4b <- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model4.4c<- MCMClogit(Consensus2 ~ Microlink_ODMB4 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model4.4 <- mcmc.list(Model4.4a, Model4.4b, Model4.4c)

Model4.5a <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=2590)

Model4.5b <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=679)

Model4.5c <- MCMClogit(Consensus2 ~ Microlink_ODMB5 + LogCouncilLink + 
	Codecision + Consensus + Regulation, data=DataSet, burnin=10000000, mcmc=20000000, 
	thin=10000, tune=.7, B0=.00001, b0=0, marginal.likelihood="Laplace", seed=9145)

Model4.5 <- mcmc.list(Model4.5a, Model4.5b, Model4.5c)

summary(Model4.1)
summary(Model4.2)
summary(Model4.3)
summary(Model4.4)
summary(Model4.5)

DrawModel4.1 <- extractCodaDraws(Model4.1)
DrawModel4.2 <- extractCodaDraws(Model4.2)
DrawModel4.3 <- extractCodaDraws(Model4.3)
DrawModel4.4 <- extractCodaDraws(Model4.4)
DrawModel4.5 <- extractCodaDraws(Model4.5)


mean(DrawModel4.1$Microlink_ODMB1>0)
mean(DrawModel4.2$Microlink_ODMB2>0)
mean(DrawModel4.3$Microlink_ODMB3>0)
mean(DrawModel4.4$Microlink_ODMB4>0)
mean(DrawModel4.5$Microlink_ODMB5>0)

mean(DrawModel4.1$LogCouncilLink>0)
mean(DrawModel4.2$LogCouncilLink>0)
mean(DrawModel4.3$LogCouncilLink>0)
mean(DrawModel4.4$LogCouncilLink>0)
mean(DrawModel4.5$LogCouncilLink>0)


################################################################################################
################################################################################################
### Figure 1 ###################################################################################
################################################################################################
################################################################################################
Draws <- c(DrawModel1.1$Microlink_ODMB1, DrawModel1.2$Microlink_ODMB2, 
			DrawModel1.3$Microlink_ODMB3, DrawModel1.4$Microlink_ODMB4, 
			DrawModel1.5$Microlink_ODMB5)	
quantile(Draws, probs=seq(0, 1, .025), type=1)
# This creates a dataset with only variables that are within a 90% credible interval. 
# It cuts out all variables within a between 5% and 95%		
TwoTailedTest <- c(rep(99, 30000))
for(i in 1:length(TwoTailedTest)){
	TwoTailedTest[i] <- ifelse(Draws[i]<.1593309, NA,
						ifelse(Draws[i]>6.392794, NA, Draws[i]))
}
TwoTailedTest <- TwoTailedTest[!is.na(TwoTailedTest)]

#Creates a sequence of potential values for micro value
MicroValue <- seq(from=-1, to=1, .01000)
MicroValue <- rep(MicroValue, length(TwoTailedTest))
MicroValue <- sort(MicroValue)

#This repeats the values in the two-tailed
Test <- c(rep(TwoTailedTest, 201))

Micro <- Test*MicroValue

PredictedPoint2 <- cbind(c(rep(NA, length(Micro))), MicroValue)
for(i in 1:length(Micro)){
	PredictedPoint2[i,1] <- exp(-1.63 + Test[i]*MicroValue[i] + 
						1.01*-.44 + 1.5150*0.15 + 1.386*0.63)/
						(1 + exp(-1.63 + Test[i]*MicroValue[i] + 
						1.01*-.44 + 1.5150*0.15 + 1.386*0.63)
						)
}	
MicroValue2 <- seq(from=-1, to=1, .01000)

PredictedPoint3 <- cbind(rep(NA, length(MicroValue2)), MicroValue2)
for(i in 1:length(MicroValue2)){
	PredictedPoint3[i,1] <- exp(-1.63 + 3.15*MicroValue2[i] + 
						1.01*-.44 + 1.5150*0.15 + 1.386*0.63)/
						(1 + exp(-1.63 + 3.222222*MicroValue2[i] + 
						1.01*-.44 + 1.5150*0.15 + 1.386*0.63)
						)
}	


plot(x=PredictedPoint2[, 2], y=PredictedPoint2[, 1], col="slategray2", xlab="Within-Agreement Linkage", ylab="Predicted Probability of Consensus", pch=16, cex=0.25)
points(x=PredictedPoint3[, 2], y=PredictedPoint3[, 1], col="black", pch=18, cex=0.75)



################################################################################################
################################################################################################
### Figure 2 ###################################################################################
################################################################################################
################################################################################################


# Make a plot
MicroLinkage <- c(.159, 3.078, 6.392)
y1 <- c(7, 7, 7)

PolicyLinkage <- c(-1.658, -.417, .686)
y2 <- c(6, 6, 6)                                 
                      
TemporalLinkage <- c(-.95, .14, 1.26)
y3 <- c(5, 5, 5)

CouncilLinkage <- c(-.201, .599, 1.72)
y4 <- c(4, 4, 4)

QMV <- c(2.24, 4.851, 8.482)
y5 <- c(3, 3, 3)

Codecision <- c(.524, 2.445, 5.220)
y6 <- c(2, 2, 2)

Regulation <-c(1.362, 3.399, 6.124)
y7 <- c(1, 1, 1)

Zero <- c(0, 0)
y8 <- c(.75, 8)

MicroLinkage.1 <- c(3.14975546)
y1.1 <- c(7)
PolicyLinkage.1 <- c(-0.56556688)
y2.1 <- c(6)
TemporalLinkage.1 <- c(.586856431)
y3.1 <- c(5)
CouncilLinkage.1 <- c(.599)
y4.1 <- c(4)
QMV.1 <- c(4.98188129)
y5.1 <- c(3)
Codecision.1 <- c(1.9724)
y6.1 <- c(2)
Regulation.1 <- c(3.3213982)
y7.1 <- c(1)


plot(x=MicroLinkage, y=y1, type="l", ylim=c(0, 7.5), 
		xlim=c(-8, 9), xlab="", main="", ylab="",
		pch=16, axes=FALSE, lwd=3)
points(MicroLinkage.1, y=y1.1, pch=16)

lines(PolicyLinkage, y=y2,lwd=3)
points(PolicyLinkage.1, y=y2.1, pch=16)


lines(TemporalLinkage, y=y3,  lwd=3)
points(TemporalLinkage.1, y=y3.1, pch=16)

lines(CouncilLinkage, y=y4,  lwd=3)
points(CouncilLinkage.1, y=y4.1, pch=16)

lines(QMV, y=y5, lwd=3)
points(QMV.1, y=y5.1, pch=16)

lines(Codecision, y=y6, lwd=3)
points(Codecision.1, y=y6.1, pch=16)

lines(Regulation, y=y7, lwd=3)
points(Regulation.1, y=y7.1, pch=16)

lines(Zero, y=y8, lty=2, lwd=.50)

axis(1, at=-2:9, cex.axis=1, las=1, pos=0, tick=TRUE, labels=c("","", "", "", "", "", "", "", "", "", "", ""), line=-11)		
